<?php
global $_GPC, $_W;
$file = $_FILES["wxpaykey"];
$idanme = 'wxpaykey';
if(empty($file)){
    $file = $_FILES["wxpaycert"];
    $idanme = 'wxpaycert';
}
$max_file_size = 2000000;
$uptypes = array('application/octet-stream');
$weid = $_W['uniacid'];
$destination_folder = $_GPC['m'] . "/inc/common/wxpay/cert/" . $weid . '/';
if (!is_uploaded_file($file['tmp_name'])) {
    $message = array('status'=>2,'msg'=>'文档不存在!');
    echo json_encode($message);exit;
}
if ($max_file_size < $file["size"]) {
    $message = array('status'=>2,'msg'=>'文件太大!');
    echo json_encode($message);exit;
}
if (!in_array($file["type"], $uptypes)) {
    $message = array('status'=>2,'msg'=>'该类型文件不能上传!');
    echo json_encode($message);exit;
}
if (!file_exists("../addons/" . $destination_folder)) {
    mkdir("../addons/" . $destination_folder, 0777, true);
}
$filename = $file["tmp_name"];
$pinfo = pathinfo($file["name"]);
$ftype = $pinfo['extension'];
$filespath = $destination_folder . $file["name"];
$destination = "../addons/" . $filespath;
if (!move_uploaded_file($filename, $destination)) {

    $message = array('status'=>2,'msg'=>'移动文件出错!');
    echo json_encode($message);exit;
}
$pinfo = pathinfo($destination);
$fname = $pinfo['basename'];
$message = array('status'=>1,'url'=>'addons/'.$destination_folder. $fname,'idname'=>$idanme);
echo json_encode($message);exit;
